# utils/config_loader.py（正确版本）
import yaml
import os
from typing import Dict

# 全局配置
_config = None

def load_config(config_path: str = "config/config.yaml") -> Dict:
    """加载配置文件"""
    global _config
    if _config is not None:
        return _config
        
    try:
        with open(config_path, "r", encoding="utf-8") as f:
            _config = yaml.safe_load(f)
        return _config
    except FileNotFoundError:
        raise
    except Exception as e:
        raise


def reload_config(config_path: str = "config/config.yaml") -> Dict:
    """强制热加载配置文件，每次都重新读取"""
    global _config
    try:
        with open(config_path, "r", encoding="utf-8") as f:
            _config = yaml.safe_load(f)
        return _config
    except FileNotFoundError:
        raise
    except Exception as e:
        raise

def get_config() -> Dict:
    """获取全局配置"""
    global _config
    if _config is None:
        load_config()
    return _config